/*
 * @lc app=leetcode.cn id=80 lang=javascript
 *
 * [80] 删除有序数组中的重复项 II
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function (nums) {
  let slow = 1;
  let cnt = 1;
  for (let i = 1; i < nums.length; i++) {
    if (nums[i] === nums[i - 1]) cnt++;
    else cnt = 1;
    if (cnt <= 2) {
      nums[slow++] = nums[i];
    }
  }
  return slow;
};
// @lc code=end
